package org.example.myleet.p501;

import org.example.myleet.Utils.TreeNode;

import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
//        Integer[] midSeqNodes = new Integer[]{1,null,2,2};
        Integer[] midSeqNodes = new Integer[]{2147483647};
        TreeNode root = parseMidSeq(midSeqNodes, 0);
        System.out.println(root);
        Solution solution = new Solution();
        int[] mode = solution.findMode(root);
        System.out.println(Arrays.toString(mode));
    }

    public static TreeNode parseMidSeq(Integer[] midSeqNodes, int index) {
        int len = midSeqNodes.length;
        if (0 > index || (len - 1) < index) {
            //out of bound
            return null;
        }
        Integer value = midSeqNodes[index];
        if (null == value) {
            return null;
        }
        TreeNode node = new TreeNode(value);
        node.left = parseMidSeq(midSeqNodes, ++index);
        node.right = parseMidSeq(midSeqNodes, ++index);
        return node;
    }
}
